/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once

#include <concurrent_vector.h>
#include <baja/simple_collection.hpp>

namespace baja {

template <class Telem>
class vector_collection : public isimple_collection<Telem>
{
public:
    vector_collection(std::vector<Telem>& v) : _vector(v) {}

    // isimple_collection<Telem>

    size_t size() { return _vector.size(); }

    const Telem& item(const size_t index)
    {
        return _vector[index];
    }

private:
    std::vector<Telem>& _vector;
};

template <class Telem>
class concurrent_vector_collection : public isimple_collection<Telem>
{
public:
    concurrent_vector_collection(concurrency::concurrent_vector<Telem>& v) : _vector(v) {}

    // isimple_collection<Telem>

    size_t size() { return _vector.size(); }

    const Telem& item(const size_t index)
    {
        return _vector[index];
    }

private:
    concurrency::concurrent_vector<Telem>& _vector;
};

template <class T> inline std::shared_ptr<isimple_collection<T>> createVectorCollection(std::vector<T>& v)
{
    std::shared_ptr<vector_collection<T>> returnValue = std::make_shared<vector_collection<T>>(v);
    return std::static_pointer_cast<isimple_collection<T>>(returnValue);
}

} // namespace baja